from fastapi import APIRouter, status
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import Request

from app.controllers.weather_forecast_controllers import (
    CreateWeatherForecastController, DeleteWeatherForecastController,
    EditWeatherForecastController, GetWeatherForecastByIdController)
from app.schemas.forecast_schemas import (CreateWeatherForecastRequestSchema,
                                          EditWeatherForecastRequestSchema,
                                          GetWeatherForecastResponseSchema)

weather_forecast_router = APIRouter(
    prefix="/region/weather/forecast", tags=["Weather forecast routers"]
)
templates = Jinja2Templates(directory="templates")


@weather_forecast_router.post("", status_code=status.HTTP_200_OK)
async def add_weather_forecast(
        request: CreateWeatherForecastRequestSchema,
) -> GetWeatherForecastResponseSchema:
    controller = CreateWeatherForecastController(request=request)
    return await controller.execute()


@weather_forecast_router.get("/front", response_class=HTMLResponse)
async def region_front(request: Request):
    return templates.TemplateResponse(
        request=request, name="forecast.html", context={"id": 1}
    )


@weather_forecast_router.get("/{forecastId}", status_code=status.HTTP_200_OK)
async def get_weather_forecast_by_id(
        forecastId: int,
) -> GetWeatherForecastResponseSchema:
    controller = GetWeatherForecastByIdController(forecast_id=forecastId)
    return await controller.execute()


@weather_forecast_router.put("/{forecastId}", status_code=status.HTTP_200_OK)
async def edit_weather_forecast(
        forecastId: int, request: EditWeatherForecastRequestSchema
) -> GetWeatherForecastResponseSchema:
    controller = EditWeatherForecastController(forecast_id=forecastId, request=request)
    return await controller.execute()


@weather_forecast_router.delete("/{forecastId}", status_code=status.HTTP_200_OK)
async def delete_weather_forecast(forecastId: int) -> None:
    controller = DeleteWeatherForecastController(forecast_id=forecastId)
    return await controller.execute()
